package com.tronsis.distribution.activity.me.upgrade;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tronsis.distribution.R;
import com.tronsis.distribution.bean.ApplyDepositBean;
import com.tronsis.distribution.biz.factory.UpgradeBizFactory;
import com.tronsis.distribution.util.StateUtil;
import com.tronsis.library.activity.ToolBarBaseActivity;
import com.tronsis.library.http.UICallBack;
import com.tronsis.library.util.ToastUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * allen: 退押申请
 */
public class ReturnApplyActivity extends ToolBarBaseActivity {
    @BindView(R.id.tv_type)
    TextView tvType;
    @BindView(R.id.ll_type)
    LinearLayout llType;
    @BindView(R.id.tv_level)
    TextView tvLevel;
    @BindView(R.id.tv_need_contribution)
    TextView tvNeedContribution;
    @BindView(R.id.tv_have_contribution)
    TextView tvHaveContribution;
    @BindView(R.id.tv_return_money)
    TextView tvReturnMoney;
    private ApplyDepositBean applyDepositBean;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_return_apply);
        ButterKnife.bind(this);
        setTitle(true, getString(R.string.apply));
        applyDepositBean = (ApplyDepositBean) getIntent().getSerializableExtra("applyDepositBean");
        initView();
    }

    private void initView() {
        tvLevel.setText(StateUtil.getLevelText(applyDepositBean.getLevel()));
        tvHaveContribution.setText(applyDepositBean.getHaveContri() + "");
        tvNeedContribution.setText(applyDepositBean.getNeedContri() + "");
        tvReturnMoney.setText(getString(R.string.format_price, applyDepositBean.getDeposit()));
    }

    @OnClick(R.id.btn_submit_apply)
    public void applyClick() {
        if(applyDepositBean.getDeposit()==0){
            ToastUtil.showToastInCenter(mContext,"您的押金已退还");
            return;
        }
        submitDeposit();
    }

    //Allen：提交退押金申请
    private void submitDeposit() {
        try {

            UpgradeBizFactory.createBiz().submitDeposit(this, new UICallBack() {
                @Override
                public void onStart() {
                    showLoadingDialog();
                }

                @Override
                public void onRefresh(Object data) {
                    dismissLoadingDialog();
                    setResult(Activity.RESULT_OK);
                    finish();
                }

                @Override
                public void onFailure(int status) {
                    dismissLoadingDialog();

                }
            });
        } catch (Exception e) {
            dismissLoadingDialog();
            e.printStackTrace();
        }
    }
}
